package com.android.danaobank.widgets;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

/**
 * ================================================
 * <p>
 * Created by ligang on 2020/8/30 0030 9:31
 * ================================================
 */
public class ChatProgressBar extends View {
    private int width;
    private Paint paint;
    private RectF ractInner;

    public ChatProgressBar(Context context) {
        super(context);
        init();
    }

    public ChatProgressBar(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        paint = new Paint();
        paint.setAntiAlias(true);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (width == 0) {
            width = getWidth();
            ractInner = new RectF(width / 10, width / 10, width - width / 10, width - width / 10);
        }
        paint.setColor(0xffff8000);
        canvas.drawCircle(width / 2, width / 2, width / 2, paint);
        paint.setColor(0xffffffff);
        canvas.drawCircle(width / 2, width / 2, width / 2 - width / 20, paint); //3

        paint.setColor(0xffff8000);
        canvas.drawArc(ractInner, 270, sweepAngle, true, paint);
    }

    private float sweepAngle;

    public void setProgress(int progress) {
        sweepAngle = progress * 360 / 100;
        invalidate();
    }
}
